/**
 * Created by gongxun on 16/10/26.
 */

var GameMsgManager = function () {
    var that = new GameMsgBase();

    //游戏模式 1 3人 2 2人
    that.kwxGameModel = 1;

    // that.test = function () {
    //     var Request = that.builder.build(hallResponse[42]);
    //     var request = new Request();
    //
    //     var test = that.getPotobufMsg(request);
    // };

    //分发包
    that.handleMsg = function (binary, msgId) {
        //开始检测连接
        mo.mainScene.startCheckOnline();

        var response = null;

        if (msgId == 0) {
            response = new HallCommonErrorHandler();
            response.handle(binary, msgId);
        } else if (msgId == 2) {
            response = new HallHHResponseHandler();
            response.handle(binary, msgId);
        } else if (msgId == 4) {
            response = new HallLoginResponseHandler();
            response.handle(binary, msgId);
        } else if (msgId == 6) {
            response = new HallLogoutResponseHandler();
            response.handle(binary, msgId);
        } else if (msgId == 7) {
            response = new HallItemChangedEvent();
            response.handle(binary, msgId);
        } else if (msgId == 11) {
            response = new HallUserChatMsgResponse();
            response.handle(binary, msgId);
        } else if (msgId == 14) {
            response = new HallUserMessageIdListResponse();
            response.handle(binary, msgId);
        } else if (msgId == 16) {
            response = new HallUserMessageResponseResponse();
            response.handle(binary, msgId);
        } else if (msgId == 18) {
            response = new HallUserMessageActionResponseResponse();
            response.handle(binary, msgId);
        } else if (msgId == 21) {
            response = new HallUserInfoResponse();
            response.handle(binary, msgId);
        } else if (msgId == 24) {
            response = new HallPushMessageResponse();
            response.handle(binary, msgId);
        } else if (msgId == 65) {
            response = new HallPlayListResponse();
            response.handle(binary, msgId);
        } else if (msgId == 69) {
            response = new HallRePlayResponse();
            response.handle(binary, msgId);
        } else if (msgId == 73) {
            response = new HallUserOnLineResponse();
            response.handle(binary, msgId);
        } else if (msgId == 77) {
            response = new HallSystimeResponse();
            response.handle(binary, msgId);
        } else if (msgId == 79) {
            response = new HallOpenTableResponse();
            response.handle(binary, msgId);
        } else if (msgId == 81) {
            response = new HallOpenTableHistoryResponse();
            response.handle(binary, msgId);
        } else if (msgId == 84) {
            response = new HallQueryUserStateResponse();
            response.handle(binary, msgId);
        } else if (msgId == 87) {
            response = new HallRedPkgWeiXingResponse();
            response.handle(binary, msgId);
        }

        //kwx
        else if (msgId == 1402) {
            response = new KwxJoinFreeResponsekwx();
            response.handle(binary, msgId);
        } else if (msgId == 1404) {
            response = new KwxActionResponsekwx();
            response.handle(binary, msgId);
        } else if (msgId == 1406) {
            response = new KwxTableStatskwx();
            response.handle(binary, msgId);
        } else if (msgId == 1408) {
            response = new KwxRoundEndedEventkwx();
            response.handle(binary, msgId);
        } else if (msgId == 1410) {
            response = new KwxForceExitTableResponsekwx();
            response.handle(binary, msgId);
        } else if (msgId == 1413) {
            response = new KwxCancleJuRequestkwx();
            response.handle(binary, msgId);
        } else if (msgId == 1414) {
            response = new KwxCancleJuResponsekwx();
            response.handle(binary, msgId);
        } else if (msgId == 1416) {
            response = new KwxGameReadyResponsekwx();
            response.handle(binary, msgId);
        } else if (msgId == 1417) {
            response = new KwxTableRunTimeResultkwx();
            response.handle(binary, msgId);
        } else if (msgId == 1420) {
            response = new KwxTablePlayStateResponsekwx();
            response.handle(binary, msgId);
        } else if (msgId == 1421) {
            response = new KwxJuEndedEventkwx();
            response.handle(binary, msgId);
        } else if (msgId == 1441) {
            response = new KwxCreateUserKickOutResponsekwx();
            response.handle(binary, msgId);
        }

        //kwxpp
        else if (msgId == 1502) {
            response = new KwxppJoinFreeResponsekwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1504) {
            response = new KwxppActionResponsekwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1506) {
            response = new KwxppTableStatskwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1508) {
            response = new KwxppRoundEndedEventkwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1510) {
            response = new KwxppForceExitTableResponsekwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1513) {
            response = new KwxppCancleJuRequestkwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1514) {
            response = new KwxppCancleJuResponsekwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1516) {
            response = new KwxppGameReadyResponsekwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1517) {
            response = new KwxppTableRunTimeResultkwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1520) {
            response = new KwxppTablePlayStateResponsekwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1521) {
            response = new KwxppJuEndedEventkwxpp();
            response.handle(binary, msgId);
        } else if (msgId == 1541) {
            response = new KwxppCreateUserKickOutResponsekwxpp();
            response.handle(binary, msgId);
        }

        //nn
        else if (msgId == 902) {
            response = new NnJoinFreeResponsenn();
            response.handle(binary, msgId);
        } else if (msgId == 904) {
            response = new NnActionResponsenn();
            response.handle(binary, msgId);
        } else if (msgId == 906) {
            response = new NnTableStatsnn();
            response.handle(binary, msgId);
        } else if (msgId == 908) {
            response = new NnRoundEndedEventnn();
            response.handle(binary, msgId);
        } else if (msgId == 910) {
            response = new NnForceExitTableResponsenn();
            response.handle(binary, msgId);
        } else if (msgId == 913) {
            response = new NnCancleJuRequestnn();
            response.handle(binary, msgId);
        } else if (msgId == 916) {
            response = new NnGameReadyResponsenn();
            response.handle(binary, msgId);
        } else if (msgId == 921) {
            response = new NnJuEndedEventnn();
            response.handle(binary, msgId);
        } else if (msgId == 922) {
            response = new NnPushRYScorenn();
            response.handle(binary, msgId);
        } else if (msgId == 941) {
            response = new NnCreateUserKickOutResponsenn();
            response.handle(binary, msgId);
        }

        //gsbdx
        else if (msgId == 2102) {
            response = new GsbdxJoinFreeResponsegsbdx();
            response.handle(binary, msgId);
        } else if (msgId == 2104) {
            response = new GsbdxActionResponsegsbdx();
            response.handle(binary, msgId);
        } else if (msgId == 2106) {
            response = new GsbdxTableStatsgsbdx();
            response.handle(binary, msgId);
        } else if (msgId == 2108) {
            response = new GsbdxRoundEndedEventgsbdx();
            response.handle(binary, msgId);
        } else if (msgId == 2110) {
            response = new GsbdxForceExitTableResponsegsbdx();
            response.handle(binary, msgId);
        } else if (msgId == 2113) {
            response = new GsbdxCancleJuRequestgsbdx();
            response.handle(binary, msgId);
        } else if (msgId == 2116) {
            response = new GsbdxGameReadyResponsegsbdx();
            response.handle(binary, msgId);
        } else if (msgId == 2121) {
            response = new GsbdxJuEndedEventgsbdx();
            response.handle(binary, msgId);
        } else if (msgId == 2122) {
            response = new GsbdxPushRYScoregsbdx();
            response.handle(binary, msgId);
        } else if (msgId == 2141) {
            response = new GsbdxCreateUserKickOutResponsettz();
            response.handle(binary, msgId);
        }

        //psz
        else if (msgId == 2202) {
            response = new PszJoinFreeResponsezjh();
            response.handle(binary, msgId);
        } else if (msgId == 2204) {
            response = new PszActionResponsezjh();
            response.handle(binary, msgId);
        } else if (msgId == 2206) {
            response = new PszTableStatszjh();
            response.handle(binary, msgId);
        } else if (msgId == 2208) {
            response = new PszRoundEndedEventzjh();
            response.handle(binary, msgId);
        } else if (msgId == 2210) {
            response = new PszForceExitTableResponsezjh();
            response.handle(binary, msgId);
        } else if (msgId == 2213) {
            response = new PszCancleJuRequestzjh();
            response.handle(binary, msgId);
        } else if (msgId == 2216) {
            response = new PszGameReadyResponsezjh();
            response.handle(binary, msgId);
        } else if (msgId == 2221) {
            response = new PszJuEndedEventzjh();
            response.handle(binary, msgId);
        } else if (msgId == 2222) {
            response = new PszPushRYScorezjh();
            response.handle(binary, msgId);
        } else if (msgId == 2241) {
            response = new PszCreateUserKickOutResponsezjh();
            response.handle(binary, msgId);
        }

        //whmj
        // else if (msgId == 2002) {
        //     response = new WhmjJoinFreeResponsewhmj();
        //     response.handle(binary, msgId);
        // } else if (msgId == 2004) {
        //     response = new WhmjActionResponsewhmj();
        //     response.handle(binary, msgId);
        // } else if (msgId == 2006) {
        //     response = new WhmjTableStatswhmj();
        //     response.handle(binary, msgId);
        // } else if (msgId == 2008) {
        //     response = new WhmjRoundEndedEventwhmj();
        //     response.handle(binary, msgId);
        // } else if (msgId == 2010) {
        //     response = new WhmjForceExitTableResponsewhmj();
        //     response.handle(binary, msgId);
        // } else if (msgId == 2013) {
        //     response = new WhmjCancelJuRequestwhmj();
        //     response.handle(binary, msgId);
        // } else if (msgId == 2014) {
        //     response = new WhmjCancelJuResponsewhmj();
        //     response.handle(binary, msgId);
        // } else if (msgId == 2016) {
        //     response = new WhmjGameReadyResponsewhmj();
        //     response.handle(binary, msgId);
        // } else if (msgId == 2017) {
        //     response = new WhmjTableRunTimeResultwhmj();
        //     response.handle(binary, msgId);
        // } else if (msgId == 2021) {
        //     response = new WhmjJuEndedEventwhmj();
        //     response.handle(binary, msgId);
        // }

        //dzpk
        else if (msgId == 2302) {
            response = new DzpkJoinFreeResponsedzpk();
            response.handle(binary, msgId);
        } else if (msgId == 2304) {
            response = new DzpkTableStatsdzpk();
            response.handle(binary, msgId);
        } else if (msgId == 2306) {
            response = new DzpkTableStatsdzpk();
            response.handle(binary, msgId);
        } else if (msgId == 2308) {
            response = new DzpkRoundEndedEventdzpk();
            response.handle(binary, msgId);
        } else if (msgId == 2310) {
            response = new DzpkForceExitTableResponsedzpk();
            response.handle(binary, msgId);
        } else if (msgId == 2313) {
            response = new DzpkCancleJuRequestdzpk();
            response.handle(binary, msgId);
        } else if (msgId == 2316) {
            response = new DzpkGameReadyResponsedzpk();
            response.handle(binary, msgId);
        } else if (msgId == 2321) {
            response = new DzpkJuEndedEventdzpk();
            response.handle(binary, msgId);
        } else if (msgId == 2343) {
            response = new DzpkLastRoundEndedEventdzpk();
            response.handle(binary, msgId);
        }

        //dtj
        else if (msgId == 2502) {
            response = new DtjJoinFreeResponsedtj();
            response.handle(binary, msgId);
        } else if (msgId == 2504) {

        } else if (msgId == 2506) {
            response = new DtjTableStatsdtj();
            response.handle(binary, msgId);
        } else if (msgId == 2508) {
            response = new DtjRoundEndedEventdtj();
            response.handle(binary, msgId);
        } else if (msgId == 2510) {
            response = new DtjForceExitTableResponsedtj();
            response.handle(binary, msgId);
        } else if (msgId == 2513) {
            response = new DtjCancleJuRequestdtj();
            response.handle(binary, msgId);
        } else if (msgId == 2516) {
            response = new DtjGameReadyResponsedtj();
            response.handle(binary, msgId);
        } else if (msgId == 2521) {
            response = new DtjJuEndedEventdtj();
            response.handle(binary, msgId);
        }

        //ddz
        else if (msgId == 2702) {
            response = new DdzJoinFreeResponseddz();
            response.handle(binary, msgId);
        } else if (msgId == 2704) {

        } else if (msgId == 2706) {
            response = new DdzTableStatsddz();
            response.handle(binary, msgId);
        } else if (msgId == 2708) {
            response = new DdzRoundEndedEventddz();
            response.handle(binary, msgId);
        } else if (msgId == 2710) {
            response = new DdzForceExitTableResponseddz();
            response.handle(binary, msgId);
        } else if (msgId == 2713) {
            response = new DdzCancleJuRequestddz();
            response.handle(binary, msgId);
        } else if (msgId == 2716) {
            response = new DdzGameReadyResponseddz();
            response.handle(binary, msgId);
        } else if (msgId == 2721) {
            response = new DdzJuEndedEventddz();
            response.handle(binary, msgId);
        }

        //pdk
        else if (msgId == 2802) {
            response = new PdkJoinFreeResponsepdk();
            response.handle(binary, msgId);
        } else if (msgId == 2804) {

        } else if (msgId == 2806) {
            response = new PdkTableStatspdk();
            response.handle(binary, msgId);
        } else if (msgId == 2808) {
            response = new PdkRoundEndedEventpdk();
            response.handle(binary, msgId);
        } else if (msgId == 2810) {
            response = new PdkForceExitTableResponsepdk();
            response.handle(binary, msgId);
        } else if (msgId == 2813) {
            response = new PdkCancleJuRequestpdk();
            response.handle(binary, msgId);
        } else if (msgId == 2816) {
            response = new PdkGameReadyResponsepdk();
            response.handle(binary, msgId);
        } else if (msgId == 2817) {
            response = new PdkTableRunTimeResultpdk();
            response.handle(binary, msgId);
        } else if (msgId == 2821) {
            response = new PdkJuEndedEventpdk();
            response.handle(binary, msgId);
        }
    };

    //发送心跳
    that.sendHH = function () {
        var msgid = 1;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.Seq = mo.gameHelper.getTimestamp();

        mo.gameWebsocket.sendMsg(that.getPotobufMsgNotLog(request), msgid);
    };

    //登录
    that.sendLogin = function (userId, session) {
        var msgid = 3;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.uid = userId;
        if (session != undefined) {
            request.sessionid = session;
        } else {
            request.sessionid = "";
        }
        if (mo.gameUserInfo.deviceInfoDesc != null) {
            var devicetype = mo.gameHelper.getDeviceType();
            var devicetext = mo.gameUserInfo.deviceInfoDesc;
            var gpsText = mo.gameUserInfo.phoneLocationCHS;
            var ipText = mo.gameUserInfo.myClientIp == null ? "127.0.0.1" : mo.gameUserInfo.myClientIp;
            var DeviceJson = {gps: gpsText, devicetype: devicetype, devicetext: devicetext, ip: ipText};
            request.DeviceJson = JSON.stringify(DeviceJson);
        }

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    that.sendTestLogin = function (userId, deviceJson, openId) {
        var msgid = 3;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.uid = userId;
        request.sessionid = "";
        request.DeviceJson = deviceJson;
        request.OpenId = openId;
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //获取打牌列表
    that.sendPlayListRequest = function (Uid) {
        var msgid = 64;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.Uid = parseInt(Uid);

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //获取打牌回放
    that.sendRePlayRequest = function (RePlayID) {
        var msgid = 68;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.RePlayID = RePlayID;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送聊天信息
    that.sendUserChatMsg = function (uid, msg, type, vmsg) {
        var msgid = 10;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.uid = uid;
        request.msg = msg;
        request.type = type;
        if (vmsg != undefined) {
            request.vmsg = vmsg;
        }

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //获取请求用户信息
    that.sendUserInfo = function () {
        var msgid = 20;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //请求所有礼包消息id
    that.sendUserMessageId = function () {
        var msgid = 13;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //请求一条礼包消息 通过id
    that.sendUserMessage = function (ids) {
        var msgid = 15;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.ids = ids;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //用户信箱操作请求
    that.sendUserMessageAction = function (msg_id, action) {
        var msgid = 17;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.msg_id = msg_id;
        request.action = action;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //请求用户消息
    that.sendUserInfoRequest = function () {
        var msgid = 20;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送bug信息反馈
    that.sendDebugInfo = function (uid, ReplayId, Text) {
        var msgid = 72;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.uid = uid;
        request.ReplayId = ReplayId;
        request.Text = Text;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //加房卡
    that.sendAddPoint = function (num) {
        var msgid = 74;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.num = num;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送用户信息
    that.sendOnDeviceJsonChange = function (str) {
        var msgid = 75;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.DeviceJson = str;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //获取服务器时间
    that.sendSysTime = function (uid) {
        var msgid = 76;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.uid = uid;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //获取已开记录
    that.sendOpenTable = function () {
        var msgid = 78;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //获取已开历史记录
    that.sendOpenTableHistory = function () {
        var msgid = 80;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //解散代开牌局
    that.sendCancleOpenTable = function (tableId) {
        var msgid = 82;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.TableId = tableId;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    that.sendQueryUserStateRequired = function (uid) {
        var msgid = 83;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.Uid = uid.toString();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    that.sendCheckUserState = function () {
        var msgid = 85;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsgNotLog(request), msgid);
    };

    that.sendRedPkgWeiXingRequired = function () {
        var msgid = 86;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //--------------------------------------------
    //kwx
    //--------------------------------------------

    that.getKwxGameMsgId = function (three, two) {
        if (that.kwxGameModel == 1) {
            return three;
        } else if (that.kwxGameModel == 2) {
            return two;
        }
    };

    //申请入局  tid:-1创建 其他：加入
    that.sendJoinFreeRequestkwx = function (uid, tid, config) {
        var msgid = 1401;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = "123";
        if (config != undefined) {
            request.KwxConfigJson = config;
        }

        mo.showWaitLayer(10);
        if (that.kwxGameModel == 2) {
            request = mo.gameHelper.replaceJsonTokwxpp(request, {});
            msgid = 1501;
        }
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //加入牌局
    that.sendJoinFreeRequestkwxJoin = function (uid, tid, pwd) {
        var msgid = 1401;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = pwd;

        mo.showWaitLayer(10);
        if (that.kwxGameModel == 2) {
            request = mo.gameHelper.replaceJsonTokwxpp(request, {});
            msgid = 1501;
        }
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //用户玩牌操作
    that.sendActionRequestkwx = function (code, cards1, cards2) {
        if (mo.kwxTable.mPlayerType == 0) {
            cc.log("录像不发消息");
            return;
        }

        var msgid = 1403;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.code = code;
        request.Cards1 = cards1;
        request.Cards2 = cards2;

        if (that.kwxGameModel == 2) {
            request = mo.gameHelper.replaceJsonTokwxpp(request, {});
            msgid = 1503;
        }
        return mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //退出牌桌
    that.sendForceExitTableRequestkwx = function () {
        var msgid = 1409;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        if (that.kwxGameModel == 2) {
            request = mo.gameHelper.replaceJsonTokwxpp(request, {});
            msgid = 1509;
        }
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送解散牌桌申请
    that.sendCancleJuRequestkwx = function (logicSeat, code) {
        var msgid = 1413;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        if (logicSeat == 1) {
            request.uid1 = code;
        } else if (logicSeat == 2) {
            request.uid2 = code;
        } else if (logicSeat == 3) {
            request.uid3 = code;
        }

        if (that.kwxGameModel == 2) {
            request = mo.gameHelper.replaceJsonTokwxpp(request, {});
            msgid = 1513;
        }
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //准备
    that.sendGameReadyRequestkwx = function (piao) {
        var msgid = 1415;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.Piao = piao;

        if (that.kwxGameModel == 2) {
            request = mo.gameHelper.replaceJsonTokwxpp(request, {});
            msgid = 1515;
        }
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //踢人
    that.sendCreateUserKickOutRequestkwx = function (uid) {
        var msgid = 1440;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.KickUid = parseInt(uid);

        if (that.kwxGameModel == 2) {
            request = mo.gameHelper.replaceJsonTokwxpp(request, {});
            msgid = 1540;
        }
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    /////nn

    //申请入局  tid:-1创建 其他：加入
    that.sendJoinFreeRequestnn = function (uid, tid, config) {
        var msgid = 901;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = "123";
        if (config != undefined) {
            request.CfgJson = config;
        }

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //加入牌局
    that.sendJoinFreeRequestnnJoin = function (uid, tid, pwd) {
        var msgid = 901;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = pwd;

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //用户玩牌操作
    that.sendActionRequestnn = function (code, Rate, Cards) {
        if (mo.nnTable.mPlayerType == 0) {
            cc.log("录像不发消息");
            return;
        }

        var msgid = 903;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.code = code;
        request.Rate = Rate;
        request.Cards = Cards;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送退出牌桌的申请
    that.sendForceExitTableRequestnn = function () {
        var msgid = 909;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送解散牌桌申请
    that.sendCancleJuRequestnn = function (logicSeat, code) {
        var msgid = 913;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        if (logicSeat == 1) {
            request.uid1 = code;
        } else if (logicSeat == 2) {
            request.uid2 = code;
        } else if (logicSeat == 3) {
            request.uid3 = code;
        } else if (logicSeat == 4) {
            request.uid4 = code;
        } else if (logicSeat == 5) {
            request.uid5 = code;
        }

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //准备
    that.sendGameReadyRequestnn = function () {
        var msgid = 915;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //踢人
    that.sendCreateUserKickOutRequestnn = function (uid) {
        var msgid = 940;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.KickUid = parseInt(uid);

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    /////gsbdx

    //申请入局  tid:-1创建 其他：加入
    that.sendJoinFreeRequestgsbdx = function (uid, tid, config) {
        var msgid = 2101;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = "123";
        if (config != undefined) {
            request.CfgJson = config;
        }

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //加入牌局
    that.sendJoinFreeRequestgsbdxJoin = function (uid, tid, pwd) {
        var msgid = 2101;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = pwd;

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //用户玩牌操作
    that.sendActionRequestgsbdx = function (code, Rate, Cards) {
        var msgid = 2103;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.code = code;
        request.Rate = Rate;
        request.Cards = Cards;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送退出牌桌的申请
    that.sendForceExitTableRequestgsbdx = function () {
        var msgid = 2109;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送解散牌桌申请
    that.sendCancleJuRequestgsbdx = function (logicSeat, code) {
        var msgid = 2113;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        if (logicSeat == 1) {
            request.uid1 = code;
        } else if (logicSeat == 2) {
            request.uid2 = code;
        } else if (logicSeat == 3) {
            request.uid3 = code;
        } else if (logicSeat == 4) {
            request.uid4 = code;
        } else if (logicSeat == 5) {
            request.uid5 = code;
        }

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //准备
    that.sendGameReadyRequestgsbdx = function () {
        var msgid = 2115;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //踢人
    that.sendCreateUserKickOutRequestgsbdx = function (uid) {
        var msgid = 2140;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.KickUid = parseInt(uid);

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    /////psz

    //申请入局  tid:-1创建 其他：加入
    that.sendJoinFreeRequestpsz = function (uid, tid, config) {
        var msgid = 2201;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = "123";
        if (config != undefined) {
            request.CfgJson = config;
        }

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //加入牌局
    that.sendJoinFreeRequestpszJoin = function (uid, tid, pwd) {
        var msgid = 2201;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = pwd;

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //用户玩牌操作
    that.sendActionRequestpsz = function (code, min, max) {
        var msgid = 2203;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.code = code;
        request.PayNumMin = min;
        request.PayNumMax = max;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送退出牌桌的申请
    that.sendForceExitTableRequestpsz = function () {
        var msgid = 2209;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送解散牌桌申请
    that.sendCancleJuRequestpsz = function (logicSeat, code) {
        var msgid = 2213;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        if (logicSeat == 1) {
            request.uid1 = code;
        } else if (logicSeat == 2) {
            request.uid2 = code;
        } else if (logicSeat == 3) {
            request.uid3 = code;
        } else if (logicSeat == 4) {
            request.uid4 = code;
        } else if (logicSeat == 5) {
            request.uid5 = code;
        }

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //准备
    that.sendGameReadyRequestpsz = function () {
        var msgid = 2215;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //踢人
    that.sendCreateUserKickOutRequestpsz = function (uid) {
        var msgid = 2240;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.KickUid = parseInt(uid);

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //--------------------------------------------
    //whmj
    //--------------------------------------------
    //申请入局  tid:-1创建 其他：加入
    that.sendJoinFreeRequestwhmj = function (uid, tid, config) {
        var msgid = 2001;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = "123";
        if (config != undefined) {
            request.whmjConfigJson = config;
        }

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //加入牌局
    that.sendJoinFreeRequestWhmjJoin = function (uid, tid, pwd) {
        var msgid = 2001;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = pwd;

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //退出牌桌
    that.sendForceExitTableRequestwhmj = function () {
        var msgid = 2009;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送解散牌桌申请
    that.sendCancleJuRequestwhmj = function (logicSeat, code) {
        var msgid = 2013;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        if (logicSeat == 1) {
            request.uid1 = code;
        } else if (logicSeat == 2) {
            request.uid2 = code;
        } else if (logicSeat == 3) {
            request.uid3 = code;
        } else if (logicSeat == 4) {
            request.uid4 = code;
        }

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //准备
    that.sendGameReadyRequestwhmj = function () {
        var msgid = 2015;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //用户玩牌操作
    that.sendActionRequestwhmj = function (code, cards1, cards2) {
        var msgid = 2003;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.code = code;
        request.Cards1 = cards1;
        request.Cards2 = cards2;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //--------------------------------------------
    //dzpk
    //--------------------------------------------
    that.sendJoinFreeRequestdzpk = function (uid, tid, config) {
        var msgid = 2301;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = "123";
        if (config != undefined) {
            request.CfgJson = config;
        }

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //加入牌局
    that.sendJoinFreeRequestdzpkJoin = function (uid, tid, pwd) {
        var msgid = 2301;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = pwd;

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //退出牌桌
    that.sendForceExitTableRequestdzpk = function () {
        var msgid = 2309;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送解散牌桌申请
    that.sendCancleJuRequestdzpk = function (logicSeat, code) {
        var msgid = 2313;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        if (logicSeat == 1) {
            request.uid1 = code;
        } else if (logicSeat == 2) {
            request.uid2 = code;
        } else if (logicSeat == 3) {
            request.uid3 = code;
        } else if (logicSeat == 4) {
            request.uid4 = code;
        } else if (logicSeat == 5) {
            request.uid5 = code;
        }

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //准备
    that.sendGameReadyRequestdzpk = function () {
        var msgid = 2315;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //用户玩牌操作
    that.sendActionRequestdzpk = function (code, min, max) {
        var msgid = 2303;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.code = code;
        request.PayNumMin = min;
        request.PayNumMax = max;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //踢人
    that.sendCreateUserKickOutRequestdzpk = function (uid) {
        var msgid = 2340;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.KickUid = parseInt(uid);

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //拉上局输赢信息
    that.sendGetLastRoundEndRequestdzpk = function () {
        var msgid = 2342;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //--------------------------------------------
    //dtj
    //--------------------------------------------

    that.sendJoinFreeRequestdtj = function (uid, tid, config) {
        var msgid = 2501;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = "123";
        if (config != undefined) {
            request.CfgJson = config;
        }

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //加入牌局
    that.sendJoinFreeRequestdtjJoin = function (uid, tid, pwd) {
        var msgid = 2501;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = pwd;

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //用户玩牌操作
    that.sendActionRequestdtj = function (code, Rate, Cards) {
        if (mo.dtjTable.mPlayerType == 0) {
            cc.log("录像不发消息");
            return;
        }

        var msgid = 2503;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.code = code;
        request.Rate = Rate;
        request.Cards = Cards;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送解散牌桌申请
    that.sendCancleJuRequestdtj = function (logicSeat, code) {
        var msgid = 2513;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        if (logicSeat == 1) {
            request.uid1 = code;
        } else if (logicSeat == 2) {
            request.uid2 = code;
        } else if (logicSeat == 3) {
            request.uid3 = code;
        } else if (logicSeat == 4) {
            request.uid4 = code;
        } else if (logicSeat == 5) {
            request.uid5 = code;
        }

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };


    //准备
    that.sendGameReadyRequestdtj = function () {
        var msgid = 2515;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //退出牌桌
    that.sendForceExitTableRequestdtj = function () {
        var msgid = 2509;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //踢人
    that.sendCreateUserKickOutRequestdtj = function (uid) {
        var msgid = 2540;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.KickUid = parseInt(uid);

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //-----------------------
    //ddz
    //-----------------------

    that.sendJoinFreeRequestddz = function (uid, tid, config) {
        var msgid = 2701;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = "123";
        if (config != undefined) {
            request.CfgJson = config;
        }

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //加入牌局
    that.sendJoinFreeRequestddzJoin = function (uid, tid, pwd) {
        var msgid = 2701;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = pwd;

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //用户玩牌操作
    that.sendActionRequestddz = function (code, pay, Cards) {
        if (mo.ddzTable.mPlayerType == 0) {
            cc.log("录像不发消息");
            return;
        }

        var msgid = 2703;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.code = code;
        request.PayNumMin = pay;
        request.Cards = Cards;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送解散牌桌申请
    that.sendCancleJuRequestddz = function (logicSeat, code) {
        var msgid = 2713;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        if (logicSeat == 1) {
            request.uid1 = code;
        } else if (logicSeat == 2) {
            request.uid2 = code;
        } else if (logicSeat == 3) {
            request.uid3 = code;
        }

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };


    //准备
    that.sendGameReadyRequestddz = function () {
        var msgid = 2715;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //退出牌桌
    that.sendForceExitTableRequestddz = function () {
        var msgid = 2709;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //踢人
    that.sendCreateUserKickOutRequestddz = function (uid) {
        var msgid = 2740;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.KickUid = parseInt(uid);

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };


    //-----------------------
    //pdk
    //-----------------------

    that.sendJoinFreeRequestpdk = function (uid, tid, config) {
        var msgid = 2801;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = "123";
        if (config != undefined) {
            request.CfgJson = config;
        }

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //加入牌局
    that.sendJoinFreeRequestpdkJoin = function (uid, tid, pwd) {
        var msgid = 2801;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.user_id = uid;
        request.table_id = tid;
        request.join_password = pwd;

        mo.showWaitLayer(10);
        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //用户玩牌操作
    that.sendActionRequestpdk = function (code, Cards) {
        if (mo.pdkTable.mPlayerType == 0) {
            cc.log("录像不发消息");
            return;
        }

        var msgid = 2803;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.code = code;
        request.Cards = Cards;

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //发送解散牌桌申请
    that.sendCancleJuRequestpdk = function (logicSeat, code) {
        var msgid = 2813;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        if (logicSeat == 1) {
            request.uid1 = code;
        } else if (logicSeat == 2) {
            request.uid2 = code;
        } else if (logicSeat == 3) {
            request.uid3 = code;
        }

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };


    //准备
    that.sendGameReadyRequestpdk = function () {
        var msgid = 2815;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //退出牌桌
    that.sendForceExitTableRequestpdk = function () {
        var msgid = 2809;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    //踢人
    that.sendCreateUserKickOutRequestpdk = function (uid) {
        var msgid = 2840;
        var Request = that.builder.build(hallRequest[msgid]);
        var request = new Request();
        request.KickUid = parseInt(uid);

        mo.gameWebsocket.sendMsg(that.getPotobufMsg(request), msgid);
    };

    return that;
};

mo.gameMsgManager = new GameMsgManager();